package com.ls.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ls.controller.orderrecord.model.QueryOrderRecordModel;
import com.ls.controller.scorerecord.model.QueryScoreRecordModel;
import com.ls.entity.OrderRecord;
import com.ls.entity.ScoreRecord;
import com.ls.entity.SmsRecord;
import com.ls.entity.SmsTemplate;
import com.ls.mapper.ScoreRecordMapper;
import com.ls.mapper.SmsRecordMapper;
import com.ls.service.IScoreRecordService;
import com.ls.service.ISmsRecordService;
import com.ls.utils.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import static com.ls.constant.SystemConstants.VALID_TRUE;

/**
 * <p>
 * 积分记录表 服务实现类
 * </p>
 *
 * @author pengyu
 * @since 2024-10-06
 */
@Slf4j
@Service
public class ScoreRecordServiceImpl extends ServiceImpl<ScoreRecordMapper, ScoreRecord> implements IScoreRecordService {
    /**
     * 查询积分记录分页列表
     */
    @Override
    public ResultData pageList(QueryScoreRecordModel model) {
        LambdaQueryWrapper<ScoreRecord> wrapper = new LambdaQueryWrapper<ScoreRecord>()
                .eq(model.getCustomerId()!=null, ScoreRecord::getCustomerId, model.getCustomerId())
                .eq(ScoreRecord::getValidFlag,VALID_TRUE)
                .orderByDesc(ScoreRecord::getRecordTime);
        Page page = new Page(model.getPageNum(), model.getPageSize());
        IPage<ScoreRecord> dtoIPage = this.baseMapper.selectPage(page, wrapper);
        //查询这些模板ID 是不是在使用中;如果在的话，就 设置 在使用中
        return ResultData.successData(dtoIPage);
    }
    /**
     * 获取积分记录详情
     */
    @Override
    public ScoreRecord getScore(Long orderRecordId) {
        //实现根据orderRecordId获取积分记录详情
        ScoreRecord scoreRecord = getOne(new LambdaQueryWrapper<ScoreRecord>()
                .eq(ScoreRecord::getValidFlag,VALID_TRUE)
                .eq(ScoreRecord::getOrderRecordId, orderRecordId));
        return scoreRecord;
    }
}
